<?php

if (!function_exists('dump')) {
    function dump() {
        call_user_func_array([\vola\Container::get('app'), 'dump'], func_get_args());
    }
}

if (!function_exists('model')) {
    /**
     * @param string $name
     * @return \vola\Model
     */
    function model($name) {
        return \vola\Container::get('app')->model($name);
    }
}

if (!function_exists('table')) {
    /**
     * @param string $name
     * @return \vola\Model
     */
    function table($name) {
        return \vola\Container::get('app')->table($name);
    }

}

if (!function_exists('env')) {
    /**
     * @param string $name
     * @param string $value
     * @return array|false|string
     * 
     */
    function env($name, $value = '') {
        if (!empty($value) && $value !== null) {
            \vola\Container::get('env')->set($name, $value);
        } else if ($value === null) {
            \vola\Container::get('env')->del($name);
        } else if (is_array($name)) {
            \vola\Container::get('env')->setArray($name);
        }
        return \vola\Container::get('env')->get($name);
    }
}


if (!function_exists('log_recore')) {
    function log_recore($name, $data = '', $type = 'log')
    {
        if ($data == '') {
            $data = $name;
            $name = 'debug';
        }
        \vola\Container::get('app')->log($name, $data, $type);
    }
}

if (!function_exists('url')) {
    function url($name, $parme = '')
    {
        return \vola\Container::get('app')->request()->url($name, $parme);
    }
}

if (!function_exists('add_action')) {

    /**
     * 添加钩子
     * @param string|mixed $name
     * @param string|mixed $callback
     * @param int $level
     */
    function add_action($name, $callback, $level = -1)
    {
        \vola\Container::get('hook')->action($name, $callback, $level);
    }
}

if (!function_exists('do_action')) {

    /**
     * 添加钩子
     * @param string|mixed $name
     * @param mixed $arg
     * @param string|mixed $callback
     */
    function do_action($name, ...$arg)
    {
        \vola\Container::get('hook')->do_action($name, $arg);
    }
}

if (!function_exists('add_filter')) {

    /**
     * 添加钩子
     * @param string|mixed $name
     * @param string|mixed $callback
     * @param int $level
     */
    function add_filter($name, $callback, $leval = -1)
    {
        \vola\Container::get('hook')->filter($name, $callback, $leval);
    }
}

if (!function_exists('do_filter')) {

    /**
     * 添加钩子
     * @param string|mixed $name
     * @param mixed $arg
     * @param string|mixed $callback
     */
    function do_filter($name, ...$arg)
    {
        return \vola\Container::get('hook')->do_filter($name, $arg);
    }
}

if (!function_exists('enqueue_script')) {

    /**
     * 加载JS
     * @param string|mixed $name
     * @param string|mixed $path 路径
     */
    function enqueue_script($name, $path = '')
    {
        if (!empty($path)) {
            \vola\Enqueue::add($name, $path, 'script');
        } else {
            \vola\Enqueue::show($name, 'script');
        }
    }
}

if (!function_exists('enqueue_style')) {

    /**
     * 加载CSS
     * @param string $name
     * @param string $path 路径
     */
    function enqueue_style($name, $path = '')
    {
        if (!empty($path)) {
            \vola\Enqueue::add($name, $path, 'style');
        } else {
            \vola\Enqueue::show($name, 'style');
        }
    }
}

if (!function_exists('includeFiles')) {
    /**
     * @param string $files
     */
    function includeFiles($files) {
        include $files;
    }
}

include 'include/help.php';
